package routers

import (
	v1 "gin-blog/api/v1"
	"gin-blog/middleware"
	"gin-blog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(middleware.Logger())
	r.Use(gin.Recovery())
	r.Use(middleware.Cors())

	needAuthorization := r.Group("api/v1")
	needAuthorization.Use(middleware.JwtToken())
	{
		//用户模块路由接口
		needAuthorization.PUT("user/:id", v1.EditUser)
		needAuthorization.DELETE("user/:id", v1.DeleteUser)

		//分类接口
		needAuthorization.POST("category/add", v1.AddCategory)
		needAuthorization.PUT("category/:id", v1.EditCategory)
		needAuthorization.DELETE("category/:id", v1.DeleteCategory)

		//文章接口
		needAuthorization.POST("article/add", v1.AddArticle)
		needAuthorization.PUT("article/:id", v1.EditArticle)
		needAuthorization.DELETE("article/:id", v1.DeleteArticle)

		//上传文件
		needAuthorization.POST("upload", v1.UpLoad)
	}

	publicRouterV1 := r.Group("api/v1")
	{
		publicRouterV1.POST("user/add", v1.AddUser)
		publicRouterV1.GET("user/get", v1.GetUserList)
		publicRouterV1.GET("category/get", v1.GetCategoryList)
		publicRouterV1.GET("article/get", v1.GetArticleList)
		publicRouterV1.GET("article/:id", v1.GetArticleInfo)
		publicRouterV1.GET("article/article-under-category/:id", v1.GetUnderCategoryArticle)
		publicRouterV1.POST("login", v1.Login)
	}

	r.Run(utils.HttpPort)
}
